<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-group lvGutter='8px' class="aui-gutter-column-lg">
    <i lv-icon="lv-icon-status-info" class="icon-top"></i>
    <span innerHtml="{{'protection_copy_help_label' | i18n}}">
    </span>
</lv-group>
<lv-form [formGroup]="formGroup" [lvLabelColon]="false" class="formGroup">
    <lv-form-item>
        <lv-form-label lvRequired>{{'common_replication_targer_cluster_label' | i18n}}</lv-form-label>
        <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
            <lv-group lvGutter="8px">
                <lv-select [lvOptions]="externalOption" class="retention-input" formControlName="external_system_id"
                    lvValueKey="clusterId">
                </lv-select>
                <button lv-button (click)="addStorage()" *ngIf="!isHcsCrossCloud">
                    {{'common_add_label'|i18n}}
                </button>
            </lv-group>
            <lv-group *ngIf="!externalOption?.length && isHcsCrossCloud" style="margin-top:4px">
                <lv-alert lvType="warning">{{'explore_op_cross_cloud_copy_tip_label' | i18n}}</lv-alert>
            </lv-group>
        </lv-form-control>
    </lv-form-item>
    <ng-container *ngIf="!isHcsUser || isHcsCrossCloud">
        <lv-form-item>
            <!-- 指定用户-->
            <lv-form-label lvRequired>
                {{ 'protection_specify_user_label' | i18n }}
            </lv-form-label>
            <lv-form-control>
                <lv-select [lvOptions]="specifyUserOptionsMap[formGroup.value.external_system_id] || []"
                    formControlName="specifyUser" lvValueKey="value" lvShowFilter lvFilterKey="label"
                    lvFilterMode="contains" class="retention-input"></lv-select>
            </lv-form-control>
        </lv-form-item>
        <!-- 认证密码-->
        <lv-form-item>
            <lv-form-label lvRequired>
                {{ 'common_password_label' | i18n }}
            </lv-form-label>
            <lv-form-control>
                <lv-group lvGutter="6px">
                    <aui-inupt-with-eye formControlName="authPassword" class="retention-input"></aui-inupt-with-eye>
                    <button lv-button [disabled]="!formGroup.value.specifyUser || !formGroup.value.authPassword"
                        (click)="authPassword()">
                        {{ 'common_auth_label' | i18n }}
                    </button>
                </lv-group>
            </lv-form-control>
        </lv-form-item>
        <!--指定目标位置-->
        <lv-form-item>
            <lv-form-label lvRequired>
                {{ 'specify_the_destination_location_label' | i18n }}
            </lv-form-label>
            <lv-form-control>
                <lv-group lvGutter="6px">
                    <lv-select [lvOptions]="backupStorageTypes()" formControlName="replication_storage_type"
                        lvValueKey="value" [ngClass]="{
                      'storage-type': !i18n.isEn,
                      'storage-type-en': i18n.isEn
                    }" [lvDisabled]="!isAuth"></lv-select>
                    <!--指定备份存储单元组-->
                    <lv-select *ngIf="
                      formGroup.value.replication_storage_type ===
                      dataMap.backupStorageTypeSla.group.value
                    " [lvOptions]="externalStorageMap[formGroup.value.specifyUser] || []"
                        formControlName="external_group_storage_id" lvValueKey="value" class="storage-value"
                        lvShowFilter lvFilterKey="label" lvFilterMode="contains" lvShowClear
                        [lvDisabled]="!isAuth"></lv-select>
                    <!--指定备份存储单元-->
                    <lv-select *ngIf="
                      formGroup.value.replication_storage_type ===
                      dataMap.backupStorageTypeSla.unit.value
                    " [lvOptions]="externalStorageUnitMap[formGroup.value.specifyUser] || []"
                        formControlName="replication_storage_id" lvValueKey="value" class="storage-value" lvShowFilter
                        lvFilterKey="label" lvFilterMode="contains" lvShowClear [lvDisabled]="!isAuth"></lv-select>
                </lv-group>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <lv-form-item *ngIf="rowItem.storage_id">
        <lv-form-label lvRequired>
            {{'insight_repository_label' | i18n}}</lv-form-label>
        <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
            <lv-group lvGutter="8px">
                <lv-select class="retention-input" [lvOptions]="externalStorage" formControlName="external_storage_id"
                    lvValueKey="uuid">
                </lv-select>
            </lv-group>
        </lv-form-control>
    </lv-form-item>
    <lv-form-item>
        <lv-form-label lvRequired>{{'common_retention_label' | i18n}}</lv-form-label>
        <lv-form-control>
            <lv-form-column>
                <lv-form-control [lvErrorTip]="retentionDurationErrorTip">
                    <input lv-input type="text" formControlName="retention_duration" class="retention-input"
                        [placeholder]="formGroup.get('duration_unit').value !== 'p'? '1~'+repUnitMap[formGroup.value.duration_unit]:''" />
                </lv-form-control>
            </lv-form-column>
            <lv-form-column>
                <lv-form-control>
                    <lv-select [lvOptions]="retentionDurations" formControlName="duration_unit" lvValueKey='value'
                        (ngModelChange)="changeTimeUnits($event)" class="unit-text">
                    </lv-select>
                </lv-form-control>
            </lv-form-column>
        </lv-form-control>
    </lv-form-item>
    <!-- 数据重删、数据压缩 -->
    <lv-form-item *ngIf="!isDistributed">
        <lv-form-label>{{'protection_link_redelete_label'
            | i18n}}</lv-form-label>
        <lv-form-control>
            <lv-switch formControlName="link_deduplication"></lv-switch>
        </lv-form-control>
    </lv-form-item>
    <lv-form-item>
        <lv-form-label>{{'system_link_compression_label'
            | i18n}}</lv-form-label>
        <lv-form-control>
            <lv-switch formControlName="link_compression"></lv-switch>
        </lv-form-control>
    </lv-form-item>
    <lv-form-item>
        <lv-form-label>
            {{'protection_job_failed_alarm_label' | i18n}}
            <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_alarm_after_failure_help_label' | i18n}}"
                lvTooltipPosition="rightTop"  class="configform-constraint"
                lvColorState='true'></i>
        </lv-form-label>
        <lv-form-control>
            <lv-switch formControlName="alarm_after_failure"></lv-switch>
        </lv-form-control>
    </lv-form-item>
</lv-form>

<ng-template #tipTpl>
    <div class="delete-operator">
        {{'protection_copy_confirm_tip_label' | i18n}}
    </div>
    <lv-group lvGutter='8px' class="mgt">
        <span class="taget-label">{{'protection_copy_target_label' | i18n}}</span>
        <span>{{_find(externalOption,{clusterId: formGroup.value.external_system_id})?.label}}</span>
    </lv-group>
</ng-template>
